package com.skaz.web.advice;

import com.skaz.bean.Result;
import com.skaz.util.Exceptions;
import com.skaz.util.Results;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static com.skaz.Constants.ERROR_STATUS_500_MSG;

/**
 * @Author: jungle
 * @Date: 2019/2/27 3:54 PM
 */
@RestControllerAdvice
@Slf4j
public class ExceptionAdvice {

    @ExceptionHandler(Exception.class)
    public Result exception(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        Throwable rootCause = Exceptions.getRootCause(ex);
        log.error(ERROR_STATUS_500_MSG, rootCause);
        return Results.failure("网络异常");
    }
}
